
'use strict';

//To support syntax defined in http://arduino.cc/en/Reference/HomePage

goog.provide('Blockly.Blocks.customs');

goog.require('Blockly.Blocks');




Blockly.Blocks['customs_digital_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_digital_pin",
      "message0": "%{BKY_CUSTOMS_DIGITAL_PIN_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "number_values",
          "check": "Number"
        }
      ],
      "inputsInline": true,
      "output": "Number",
      "category": Blockly.Categories.operators,
        "extensions": ["colours_control", "output_number"]
    });
  }
};

Blockly.Blocks['customs_analog_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_analog_pin",
      "message0": "%{BKY_CUSTOMS_ANALOG_PIN_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_show_highlow'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_show_highlow",
      "message0": "%{BKY_CUSTOMS_SHOW_HIGHLOW} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "d_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_HEXAGONAL,
        "extensions": ["colours_control","output_boolean"]
    });
  }
};

Blockly.Blocks['customs_digital_write'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_digital_write",
      "message0": "%{BKY_CUSTOMS_DIGITAL_WRITE}",
      "args0": [
        {
          "type": "input_value",
          "name": "pin",
          "check": "Number"
        },
        {
          "type": "input_value",
          "name": "p_value",
          "check": "Boolean"
        }
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};

Blockly.Blocks['customs_digital_read'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_digital_read",
      "message0": "%{BKY_CUSTOMS_DIGITAL_READ}",
      "args0": [
        {
          "type": "input_value",
          "name": "pin",
          "check": "Number"
        }
      ],
      "inputsInline": true,
      "output": "Boolean",
      "extensions": ["colours_control", "output_number"]
    });
  }
};

Blockly.Blocks['customs_analog_write'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_analog_write",
      "message0": "%{BKY_CUSTOMS_ANALOG_WRITE}",
      "args0": [
        {
          "type": "input_value",
          "name": "pin",
          "check": "String"
        },
        {
          "type": "input_value",
          "name": "p_value",
          "check": "Number"
        }
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};

Blockly.Blocks['customs_analog_read'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_analog_read",
      "message0": "%{BKY_CUSTOMS_ANALOG_READ} ",
      "args0": [
        {
          "type": "input_value",
          "name": "pin",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "Number",
      "extensions": ["colours_control", "output_number"]
    });
  }
};

Blockly.Blocks['customs_pulse_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_pulse_pin",
      "message0": "%{BKY_CUSTOMS_PULSE_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Roller_switch_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Roller_switch_pin",
      "message0": "%{BKY_CUSTOMS_ROLLER_SWITCH_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Key_switch_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Key_switch_pin",
      "message0": "%{BKY_CUSTOMS_KEY_SWITCH_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Action_triggering_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Action_triggering_pin",
      "message0": "%{BKY_CUSTOMS_ACTION_TRIGGERING_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Photosensitive_triggering_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Photosensitive_triggering_pin",
      "message0": "%{BKY_CUSTOMS_PHOTOSENSITIVE_TRIGGERIONG_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Magnetic_switch_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Magnetic_switch_pin",
      "message0": "%{BKY_CUSTOMS_MAGNETIC_SWITCH_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Touch_switch_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Touch_switch_pin",
      "message0": "%{BKY_CUSTOMS_TOUCH_SWITCH_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Threshold_trigger_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Threshold_trigger_pin",
      "message0": "%{BKY_CUSTOMS_THRESHOLD_TRIGGER_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_potentiometer_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_potentiometer_pin",
      "message0": "%{BKY_CUSTOMS_POTENTIOMETER_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Pressure_sensing_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Pressure_sensing_pin",
      "message0": "%{BKY_CUSTOMS_PRESSURE_SENSING_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Photosensitive_sensor_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Photosensitive_sensor_pin",
      "message0": "%{BKY_CUSTOMS_PHOTOSENSITIVE_SENSOR_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Sound_sensor_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Sound_sensor_pin",
      "message0": "%{BKY_CUSTOMS_SOUND_SENSOR_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Grayscale_detection_module_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Grayscale_detection_module_pin",
      "message0": "%{BKY_CUSTOMS_GRAYSCALE_DETECTION_MODULE_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Remote_sensing_module_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Remote_sensing_module_pin",
      "message0": "%{BKY_CUSTOMS_REMOTE_SENSING_MODULE_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Ultrasonic_range_finder_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Ultrasonic_range_finder_pin",
      "message0": "%{BKY_CUSTOMS_ULTRASONIC_RANGE_FINDER_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};

Blockly.Blocks['customs_Sliding_rheostat_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Sliding_rheostat_pin",
      "message0": "%{BKY_CUSTOMS_SLIDING_RHEOSTAT_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};


Blockly.Blocks['customs_Infrared_detector_pin'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_Sliding_rheostat_pin",
      "message0": "%{BKY_CUSTOMS_INFRARED_DETECTOR_MSG} %1",
      "args0": [
        {
          "type": "input_value",
          "name": "string_values",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "output": "String",
      "outputShape": Blockly.OUTPUT_SHAPE_SQUARE,
        "extensions": ["colours_control", "output_string"]
    });
  }
};




Blockly.Blocks['customs_motor_m'] = {
  init: function() {
    this.jsonInit({
        "type": "customs_motor_m",
        "message0": "%1",
        "args0": [
          {
            "type": "field_dropdown",
            "name": "text_values",
            "options": [
              ["M1","M1"], ["M2","M2"]
            ]
          }
        ],
        "output": "String",
        "extensions": ["colours_control", "output_string"]
      });
  }
};


Blockly.Blocks['customs_motor_direction'] = {
  init: function() {
    this.jsonInit({
        "type": "customs_motor_direction",
        "message0": "%1",
        "args0": [
          {
            "type": "field_dropdown",
            "name": "text_values",
            "options": [
              ["%{BKY_CUSTOMS_FORWARD_MSG}","F"], ["%{BKY_CUSTOMS_REVERSAL_MSG}","R"]
            ]
          }
        ],
        "output": "String",
        "extensions": ["colours_control", "output_string"]
      });
  }
};



Blockly.Blocks['customs_servo_motor_single'] = {
  init: function () {
     this.jsonInit({
      "type": "customs_servo_motor_single",
      "message0": "%{BKY_CUSTOMS_SET_MOTOR_MSG} %1 %2 %3 %{BKY_CUSTOMS_DIRECTION_MSG} %4 %{BKY_CUSTOMS_SPEED_MSG} %5",
      "args0": [
        {
          "type": "field_image",
          "src": "../../../blockly/media/motor.jpg",
          "width": 64,
          "height": 64,
          "alt": "*"
        },
        {
          "type": "input_dummy"
        },
        {
          "type": "input_value",
          "name": "MOTOR_M",
          "check": "String"
        },
        {
          "type": "input_value",
          "name": "DIRECTION_SET",
          "check": "String"
        },
        {
          "type": "input_value",
          "name": "SPEED_SET_VAL",
          "check": "Number"
        }
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};


Blockly.Blocks['customs_two_motor_direction'] = {
  init: function() {
    this.jsonInit({
        "type": "customs_two_motor_direction",
        "message0": "%1",
        "args0": [
          {
            "type": "field_dropdown",
            "name": "text_values",
            "options": [
              ["%{BKY_CUSTOMS_FORWARD_MSG}","F"], ["%{BKY_CUSTOMS_REVERSAL_MSG}","B"], ["%{BKY_CUSTOMS_LEFT_MSG}","L"],["%{BKY_CUSTOMS_RIGHT_MSG}","R"]
            ]
          }
        ],
        "output": "String",
        "extensions": ["colours_control", "output_string"]
      });
  }
};


Blockly.Blocks['customs_two_motor_speed'] = {
  init: function() {
    this.jsonInit({
        "type": "customs_two_motor_speed",
        "message0": "%1",
        "args0": [
          {
            "type": "field_dropdown",
            "name": "text_values",
            "options": [
              ["255","255"], ["100","100"], ["50","50"], ["0","0"]
            ]
          }
        ],
        "output": "String",
        "extensions": ["colours_control", "output_string"]
      });
  }
};


Blockly.Blocks['customs_servo_motor_two'] = {
  init: function () {
     this.jsonInit({
      "type": "customs_servo_motor_two",
      "message0": "%{BKY_CUSTOMS_DOUBLE_MOTOR_MSG} %1 %2 %3 %{BKY_CUSTOMS_SPEED_MSG} %4",
      "args0": [
        {
          "type": "field_image",
          "src": "../../../blockly/media/two_motor.png",
          "width": 64,
          "height": 64,
          "alt": "*"
        },
        {
          "type": "input_dummy"
        },
        {
          "type": "input_value",
          "name": "MOTOR_M",
          "check": "String"
        },
        {
          "type": "input_value",
          "name": "SPEED_SET",
          "check": "String"
        }
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};


Blockly.Blocks['customs_oled_single'] = {
  init: function () {
     this.jsonInit({
      "type": "customs_oled_single",
      "message0": "%{BKY_CUSTOMS_OLED_SINGLE_MSG}",
      "args0": [
        {
          "type": "input_dummy",
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "DISPLAY_TEXT",
          "check": [
            "Number",
            "String"
          ],
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "ROW_X",
          "check": "Number",
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "COLUMN_Y",
          "check": "Number",
          "align": "RIGHT"
        }
      ],
      "inputsInline": false,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};


Blockly.Blocks['customs_oled_display'] = {
  init: function () {
     this.jsonInit({
      "type": "customs_oled_display",
      "message0": "%{BKY_CUSTOMS_OLED_DISPLAY_MSG}",
      "args0": [
        {
          "type": "input_dummy",
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "TEXT_ONE",
          "check": [
            "Number",
            "String"
          ],
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "TEXT_TWO",
          "check": [
            "Number",
            "String"
          ],
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "TEXT_THREE",
          "check": [
            "Number",
            "String"
          ],
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "TEXT_FOUR",
          "check": [
            "Number",
            "String"
          ],
          "align": "RIGHT"
        }
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};


var TONE_NOTES=[["NOTE_C3", "131"],["NOTE_D3", "147"],["NOTE_E3", "165"],["NOTE_F3", "175"],["NOTE_G3", "196"],["NOTE_A3", "220"],["NOTE_B3", "247"],
           ["NOTE_C4", "262"],["NOTE_D4", "294"],["NOTE_E4", "330"],["NOTE_F4", "349"],["NOTE_G4", "392"],["NOTE_A4", "440"],["NOTE_B4", "494"],
           ["NOTE_C5", "532"],["NOTE_D5", "587"],["NOTE_E5", "659"],["NOTE_F5", "698"],["NOTE_G5", "784"],["NOTE_A5", "880"],["NOTE_B5", "988"]];

Blockly.Blocks['customs_tone_rhythm'] = {
  init: function() {
    this.jsonInit({
        "type": "customs_tone_rhythm",
        "message0": "%1",
        "args0": [
          {
            "type": "field_dropdown",
            "name": "number_values",
            "options": TONE_NOTES
          }
        ],
        "output": "Number",
        "extensions": ["colours_control", "output_number"]
      });
  }
};

Blockly.Blocks['customs_play_sound'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_play_sound",
      "message0": "%{BKY_CUSTOMS_PLAY_SOUND}",
      "args0": [
        {
          "type": "input_dummy"
        },
        {
          "type": "input_value",
          "name": "tone_play",
          "check": "Number",
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "frequency",
          "check": "Number",
          "align": "RIGHT"
        }
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};


Blockly.Blocks['customs_play_sound_duration'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_play_sound_duration",
      "message0": "%{BKY_CUSTOMS_PLAY_SOUND_DURATION}",
      "args0": [
        {
          "type": "input_dummy"
        },
        {
          "type": "input_value",
          "name": "tone_play",
          "check": "Number",
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "frequency",
          "check": "Number",
          "align": "RIGHT"
        },
        {
          "type": "input_value",
          "name": "otime",
          "check": "Number"
        }
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};

Blockly.Blocks['customs_stop_sound'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_stop_sound",
      "message0": "%{BKY_CUSTOMS_STOP_SOUND}",
      "args0": [
        {
          "type": "input_dummy"
        },
        {
          "type": "input_value",
          "name": "PIN",
          "check": "Number",
          "align": "RIGHT"
        }
      ],
      "inputsInline": true,
      "previousStatement": null,
      "nextStatement": null,
      "extensions": ["colours_control", "shape_statement"]
    });
  }
};



Blockly.Blocks['customs_temperature_read'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_temperature_read",
      "message0": "%{BKY_CUSTOMS_TEMPERATURE_READ}",
      "args0": [
        {
          "type": "input_value",
          "name": "pin",
          "check": "Number"
        }
      ],
      "inputsInline": true,
      "output": "Number",
      "extensions": ["colours_control", "output_number"]
    });
  }
};


Blockly.Blocks['customs_humidity_read'] = {
  init: function() {
    this.jsonInit({
      "type": "customs_humidity_read",
      "message0": "%{BKY_CUSTOMS_HUMIDITY_READ}",
      "args0": [
        {
          "type": "input_value",
          "name": "pin",
          "check": "Number"
        }
      ],
      "inputsInline": true,
      "output": "Number",
      "extensions": ["colours_control", "output_number"]
    });
  }
};
